#if TOOLS
using Godot;
using System;
using System.Collections.Generic;

namespace Darksky.GodotAddons.GizmosDisplay;


[Tool]
public partial class GizmosDisplay : EditorPlugin
{
	private List<string> _registeredTypes;

	public override void _EnterTree()
	{
		_registeredTypes = [];
		// Initialization of the plugin goes here.
		RegisterCustomNode(
			"RectGizmos", "Node2D",
			"res://addons/gizmos_display/rect_gizmos/RectGizmos.cs",
			"res://addons/gizmos_display/rect_gizmos/RectGizmos.png"
		);
	}

	public override void _ExitTree()
	{
		// Clean-up of the plugin goes here.
		foreach (var type in _registeredTypes)
		{
			RemoveCustomType(type);
		}
	}

	private void RegisterCustomNode(
		string name,
		string baseNode,
		string scriptPath,
		string iconPath)
	{
		Script script = GD.Load<Script>(scriptPath);
		Texture2D icon = GD.Load<Texture2D>(iconPath);
		AddCustomType(name, baseNode, script, icon);
		_registeredTypes.Add(name);
	}
}
#endif
